package cn.whuc.homework

object Case05 {
  def main(args: Array[String]): Unit = {
    val datas: Iterator[String] = scala.io.Source.fromFile("input/primary_midsemester.txt").getLines()
    //    for (elem <- datas.drop(1)) {
    //      println(elem)
    //    }
    val datas1: Iterator[String] = datas.drop(1)
    val courses: Iterator[(Int, Int, Int)] = datas1.map(line => {
      val strings: Array[String] = line.split(" ")
      (strings(2).toInt, strings(3).toInt, strings(4).toInt)
    })

    val courseList: List[(Int, Int, Int)] = courses.toList

    val size: Int = courseList.size

    println(courseList)

    var result1:Double = 0
    var result2:Double = 0
    var result3:Double = 0
    for (elem <- courseList) {
      result1+=elem._1
      result2+=elem._2
      result3+=elem._3
    }

//    println(courses.toList.size)

//    println(result1)
    val avg1 :Double= result1/size
    val avg2 :Double= result2/size
    val avg3 :Double= result3/size

    println(avg1)
    println(avg2)
    println(avg3)

    println(courseList)

    val chinese: List[(Int, Int, Int)] = courseList.sortBy(t => {
      t._1
    })
    val chineseLow: Int = chinese.head._1
    val chineseHigh: Int = chinese.last._1

    println(chineseLow)
    println(chineseHigh)


  }
}
